package com.seven.good.scheduler;

import com.seven.good.dao.BidRecordMapper;
import com.seven.good.server.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Description：轮询数据库中的竞拍记录表，如果行数变化，发送消息给WebSocket
 * @Author: ytj
 * @CreateDate:  19/10/24
 */
@Component
public class IsUpdateSchduler {

    @Autowired
    BidRecordMapper bidRecordMapper;

    @Autowired
    WebSocketServer webSocketServer;

    private int oldNum;
    private int newNum;
    private boolean stopMe = true;

    public void stopMe(){
        stopMe = false;
    }

    @Scheduled(cron = "0/1 * * * * ?")
    public void findIsUpdate() {
        //WebSocketServer wbs=new WebSocketServer();
        if(stopMe){
            newNum=bidRecordMapper.countRecords();
            if(oldNum!=newNum){
                oldNum=newNum;
                webSocketServer.onMessage("200");
            }
        }
    }
}
